<?php
/**
 * Created by PhpStorm.
 * User: Guo
 * Date: 2017/6/25
 * Time: 7:55
 */

namespace app\common\model;

use traits\model\SoftDelete;

class Article extends BaseModel
{
    protected $table = 'ng_articles';

    protected $createTime = 'created_at';
    protected $updateTime = 'updated_at';
    protected $autoWriteTimestamp = 'datetime';
    use SoftDelete;

    protected $deleteTime = 'deleted_at';

    protected $hidden = ['create_time', 'delete_time', 'update_time'];

    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id');
    }
    
    public function categories()
    {
        return $this->hasMany('CategoryArticle', 'article_id', 'id');
    }

    public function tags()
    {
        return $this->hasMany('ArticleTag', 'article_id', 'id');
    }
    
    public function comments()
    {
        return $this->hasMany('Comment')->field('id,article_id');
    }

    public function image()
    {
        return $this->hasOne('Image', 'id', 'image_id');
    }
}